package com.wg.core.serialize.impl;

import com.alibaba.fastjson2.JSON;
import com.wg.core.serialize.ISerializer;
import com.wg.core.serialize.SerializeType;

/**
 * FastJSON 序列化器
 *
 * <p>
 * 实现了 {@link ISerializer} 接口，使用 FastJSON 库进行对象的序列化和反序列化。
 * </p>
 *
 * @author 少爷123
 */
public class FastJsonSerializer implements ISerializer {

    @Override
    public byte[] serialize(Object obj) throws Exception {
        return JSON.toJSONBytes(obj);
    }

    @Override
    public <T> T deserialize(byte[] data, Class<T> clazz) throws Exception {
        return JSON.parseObject(data, clazz);
    }

    @Override
    public int getType() {
        return SerializeType.JSON.getType();
    }
}
